import Vue from 'vue'

const mutations = {
  // 清除状态
  RESET_STATUS (state) {
    Vue.set(state, 'actionStatus', false)
    Vue.set(state, 'succMsg', '')
    Vue.set(state, 'failMsg', '')
  },
  // 短信发送成功
  SMSSEND_SUCCESS (state, {msg}) {
    Vue.set(state, 'smsSendStatus', true)
    Vue.set(state, 'succMsg', msg)
  },
  // 短信发送失败
  SMSSEND_FAILED (state, {msg}) {
    Vue.set(state, 'failMsg', msg)
  },
  // 获取浮点基础信息
  GET_BASEINFO_SUCCESS (state, {data}) {
    Vue.set(state, 'baseInfo', data)
  },
  // 获取用户信息
  GET_USERDETAIL_SUCCESS (state, {data}) {
    Vue.set(state, 'userDetail', data)
  },
  // 清除礼包列表
  CLEAR_GIFTLIST (state) {
    Vue.set(state, 'giftList', {
      count: 0,
      list: [],
      page: 0
    })
  },
  // 获取礼包列表
  GET_GIFTLIST_SUCCESS (state, {data}) {
    concatList(state, 'giftList', data)
  },
  // 获取礼包详情
  GET_GIFTDETAIL_SUCCESS (state, {data}) {
    Vue.set(state, 'giftDetail', data)
  },
  // 领取礼包
  ADD_GIFT_SUCCESS (state, {data}) {
    Vue.set(state, 'giftDetail', data)
    Vue.set(state, 'actionStatus', true)
  },
  // 获取资讯列表
  GET_NEWSLIST_SUCCESS (state, {data}) {
    Vue.set(state, 'newsList', data)
  },
  // 清除资讯详情
  CLEAR_NEWSDETAIL (state) {
    Vue.set(state, 'newsDetail', {})
    Vue.set(state, 'msgDetail', {})
  },
  // 获取资讯详情
  GET_NEWSDETAIL_SUCCESS (state, {data}) {
    Vue.set(state, 'newsDetail', data)
  },
  // 获取我的消息列表
  GET_MSGLIST_SUCCESS (state, {data}) {
    concatList(state, 'msgList', data)
  },
  // 代金券列表单游券
  COUPONLIST_SINGLE_SUCCESS (state, {data}) {
    Vue.set(state, 'couponSingleList', data)
  },
  // 代金券列表通用券
  COUPONLIST_GENERAL_SUCCESS (state, {data}) {
    Vue.set(state, 'couponGeneralList', data)
  },
  // 领取代金券
  RECEIVE_COUPON_SUCCESS (state, {data}) {
    Vue.set(state, 'receiveCoupon', data)
    Vue.set(state, 'actionStatus', true)
  },
  // 游戏币充值
  GM_RECHARGE_SUCCESS (state, {data}) {
    Vue.set(state, 'gmRecharge', data)
  },
  // 选择支付方式进行支付
  GM_PAYPOST_SUCCESS (state, {data}) {
    Vue.set(state, 'gmPayPost', data)
  },
  // 获取游戏币充值记录
  GET_GMRECHARGE_SUCCESS (state, {data}) {
    concatList(state, 'gmRechargeList', data)
  },
  // 获取充值
  GET_ORDERLIST_SUCCESS (state, {data}) {
    concatList(state, 'orderList', data)
  },
  CLEAR_LIST (state) {
    Vue.set(state, 'gmRechargeList', '')
    Vue.set(state, 'orderList', '')
    Vue.set(state, 'msgList', {count: 0, list: [], page: 0})
  },
  // 实名认证
  SET_IDENTIFY_SUCCESS (state, {data}) {
    Vue.set(state.userDetail, 'has_identify', data.data.is_auth)
    Vue.set(state.userDetail, 'real_name', data.data.real_name)
    Vue.set(state.userDetail, 'id_card', data.data.id_card)
    Vue.set(state, 'actionStatus', true)
  },
  // 获取我的小号列表
  GET_ACCOUNTLIST_SUCCESS (state, {data}) {
    Vue.set(state, 'accountList', data)
  },
  // 选择支付方式进行支付
  REPAY_PAYPOST_SUCCESS (state, {data}) {
    Vue.set(state, 'rePayPost', data)
  },
  // 操作成功
  ACTION_SUCCESS (state, {msg}) {
    Vue.set(state, 'succMsg', msg)
    Vue.set(state, 'actionStatus', true)
  },
  // 操作失败
  ACTION_FAILED (state, {msg}) {
    Vue.set(state, 'failMsg', msg)
  },
  // 获取用户密保信息
  BIND_INFO_SUCCESS (state, {data}) {
    Vue.set(state, 'bindInfo', data)
  },
  // 改变loading状态
  UPDATE_LOADING_STATUS (state, payload) {
    state.isLoading = payload.isLoading
  },
  // 改变sdkVersion
  UPDATE_SDK_VERSION (state, sdkVersion) {
    Vue.set(state, 'sdkVersion', sdkVersion)
  },
  // 找回密码发送短信
  DEVICE_SENDSMS_SUCCESS (state, {data}) {
    Vue.set(state, 'deviceSendSms', data)
  }
}

function concatList (state, name, data) {
  let oldData = state[name] || {count: 0, list: [], page: 0}
  oldData.count = data.count
  oldData.list = oldData.list.concat(data.list)
  oldData.page++
  Vue.set(state, name, oldData)
}

export default mutations
